/*
 * @Author: jiangjinchi 1468922694@qq.com
 * @Date: 2023-06-27 10:56:02
 * @LastEditors: jiangjinchi 1468922694@qq.com
 * @LastEditTime: 2023-12-04 11:09:31
 * @FilePath: \frontEnds\src\utils\data.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import axios from "axios";
import { Message, Notification } from 'element-ui'
import Cookies from 'js-cookie'


Vue.prototype.methExportExcel = async function (meth, url, data, name) {
    let names = Cookies.get('tokenNameEqu');
    let value = Cookies.get('tokenValueEqu');
    let params = {};
    params[names] = value;
    await axios({
        method: meth,
        url: window.PLATFROM_CONFIG.url + url,
        responseType: "blob",
        data: data,
        headers: params
    }).then((res) => {
        const aEle = document.createElement("a");
        const href = window.URL.createObjectURL(res.data);
        aEle.href = href;
        aEle.download = `${name}.xlsx`;
        document.body.appendChild(aEle);
        aEle.click();
        document.body.removeChild(aEle);
        window.URL.revokeObjectURL(href);
        Message({
            message: '导出成功',
            type: 'success',
            duration: 5 * 1000
        })
    }).catch((res) => {

        Message({
            message: '导出失败，请重试',
            type: 'error',
            duration: 5 * 1000
        })

    });
    return false;
}

Vue.prototype.methDownFile = async function (meth, url, data = {}, name, fileType) {
    let names = Cookies.get('tokenNameEqu');
    let value = Cookies.get('tokenValueEqu');
    let params = {};
    params[names] = value;
    await axios({
        method: meth,
        url: window.PLATFROM_CONFIG.url + url,
        responseType: "blob",
        data: data,
        headers: params
    }).then((res) => {
        const aEle = document.createElement("a");
        const href = window.URL.createObjectURL(res.data);
        aEle.href = href;
        aEle.download = `${name}.${fileType}`;
        document.body.appendChild(aEle);
        aEle.click();
        document.body.removeChild(aEle);
        window.URL.revokeObjectURL(href);
        Message({
            message: '下载成功',
            type: 'success',
            duration: 5 * 1000
        })
    }).catch((res) => {
        Message({
            message: '下载失败，请重试',
            type: 'error',
            duration: 5 * 1000
        })

    });
    return false;
}

Vue.prototype.dateTimeTamp = function (date) {
    let dates = new Date(date).getTime()
    return dates

}

export default {
    init() {
    }
}
